<?php
include('image_upload.inc');
require 'ShopDAO.inc';
if (isset($_REQUEST['scan']))
{	
	$isSuccess;
	// 声明一个上传类
	$upfos = new image_upload('file', 'images');

	/**
	 * 建议使用随机生成的文件名，以避免上传重名的文件。
	 * 例如： $upfos->upload ( $upfos->newName());
	 */
	// 上传文件
	$isSuccess = $upfos->upload($upfos->newName());

	// 生成缩略图
	$isSuccess = $upfos->thumb('thumbnail-',200, 150);
	
	$uploadedimage = $upfos->filePath();
	$uploadedThumbImage = $upfos->thumbMap();
	$imageid = trim($_POST['imageid']);
	$image = trim($_POST['image']);
	$thumbimage = trim($_POST['thumbimage']);
	$shopid = trim($_POST['shopid']);
	
	if ($isSuccess) {
		//删除之前图片
		unlink($image);
		unlink($thumbimage);
		
		$query = "UPDATE images SET imageurl='$uploadedimage',thumb_imageurl='$uploadedThumbImage' WHERE image_id=".$imageid;
		mysql_query($query);
		
		echo "图片修改成功！<hr><p>";
		echo "<br><a href='viewImages.php?shopid=".$shopid."'>返回图片列表</a>";
	}
	else
	{
		echo "<script language=javascript>alert('图片修改失败'); history.go(-1)</script>";
	}
}
?>